﻿Public Class frmPermisos
    Dim per As New clsPermisos
    Dim Bitacora As New clsActividad

    Private Sub frmPermisos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip2.Cursor = Cursors.Hand
        ToolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        ToolStrip2.Stretch = True

        Me.txtFolio.Text = (BuscarIntDatoCitra("SELECT MAX(IdPermiso) As ID FROM Permisos")) + 1
        Me.txtIDEmpleado.Text = EmpleadoID
        Me.txtNombre.Text = frmModuloEmpleadosDetalle.txtPaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtMaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtNombre.Text.Trim
        Me.datFecha.Value = Now()
        Me.txtObservaciones.Clear()
    End Sub
    Sub gather()
        per.idPermiso = Me.txtFolio.Text
        per.idempleado = Me.txtIDEmpleado.Text
        per.Dia = Me.datFecha.Value
        per.Horario = "De " & datInicial.Text & " a " & datFinal.Text
        per.Tipo = Me.lstTipo.Text
        per.Observaciones = Me.txtObservaciones.Text
        per.Capturo = usuarioactivo
        per.Reportado = "No"

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Me.lstTipo.Text = "" Then
            MsgBox("Debes indicar el tipo de permiso", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        If datFinal.Value < datInicial.Value Then
            MsgBox("El horario final no puede ser menor al horario inicial", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        gather()
        per.Insertar()

        Bitacora.RegistraActividad("Registró un permiso nuevo a " & txtNombre.Text.Trim)

        frmModuloEmpleadosDetalle.cargaPermisos()
        MsgBox("Guardado Éxitoso", MsgBoxStyle.Information, "Aviso")
        Me.Close()

    End Sub

    Private Sub toolGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub toolSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub ToolStripButton5_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton5.Click
        If Me.lstTipo.Text = "" Then
            MsgBox("Debes indicar el tipo de permiso", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        If datFinal.Value < datInicial.Value Then
            MsgBox("El horario final no puede ser menor al horario inicial", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        gather()
        per.Insertar()

        Bitacora.RegistraActividad("Registró un permiso nuevo a " & txtNombre.Text.Trim)

        frmModuloEmpleadosDetalle.cargaPermisos()
        Me.Close()
    End Sub

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
        Close()

    End Sub
End Class